//------------------------------------------------------------------------
// <copyright file="MetaDataRow.cs" company="DevDir">
//   Copyleft (c) DevDir. No rights reserved.
// </copyright>
// <author>Nikita Sharov</author>
//------------------------------------------------------------------------

namespace DevDir.Mp3
{
  using System;
  using System.Data;
  
  public class MetaDataRow : DataRow
  {
    private MetaDataTable table;
    private MetaDataFile file;

    internal MetaDataRow(DataRowBuilder rb)
      : base(rb)
    {
      table = (MetaDataTable)this.Table;
    }

    public MetaDataFile File
    {
      get { return this.file; }
    }

    public void Set(MetaDataFile file)
    {
      if (this.file != file)
      {
        this.file = file;
        
        // HACK: Bad naming (items), unsecure element access.
        this.Set(file.Items[0]);
      }
    }

    public void Set(MetaData metaData)
    {
      if (metaData.Album != null)
      {
        this[table.AlbumColumn] = metaData.Album;
      }

      if (metaData.Artist != null)
      {
        this[table.ArtistColumn] = metaData.Artist;
      }

      if (metaData.Disc != null)
      {
        this[table.DiscColumn] = metaData.Disc;
      }

      if (metaData.DiscCount != null)
      {
        this[table.DiscCountColumn] = metaData.DiscCount;
      }

      if (metaData.Duration != null)
      {
        this[table.DurationColumn] = metaData.Duration;
      }

      if (metaData.Genre != null)
      {
        this[table.GenreColumn] = metaData.Genre;
      }

      if (metaData.Title != null)
      {
        this[table.TitleColumn] = metaData.Title;
      }

      if (metaData.Track != null)
      {
        this[table.TrackColumn] = metaData.Track;
      }

      if (metaData.TrackCount != null)
      {
        this[table.TrackCountColumn] = metaData.TrackCount;
      }

      if (metaData.Year != null)
      {
        this[table.YearColumn] = metaData.Year;
      }
    }
  }
}
